/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.leospa.clients;

/**
 *
 * @author ADMIN
 */
import java.awt.HeadlessException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

import javax.swing.JOptionPane;

import com.leospa.properties.ConfigPropertiesFile;



public class DateClient {

	public static String SocketInterface(String serverAddress, int port, String cmd, int timeout_ms){		
		try {	
			Socket s = new Socket(serverAddress, port);	        
	        s.setSoTimeout(timeout_ms);	
	        PrintWriter output = new PrintWriter(s.getOutputStream(), true);
	        BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));	        
	        output.println(cmd);
	        String answer = input.readLine();
	        input.close();
	        output.close();
	        s.close();
	        return answer;
	    } catch (Exception e) {
	    	if(ConfigPropertiesFile.DEBUG_MODE_ON == true){System.out.println("Problem At the Time Connect To Database: "+e.getMessage());}
	    	e.printStackTrace();
	    }
		return null;
	}
	
	
	
	
	
	/**
	 * @param args
	 */
	/*public static void main(String[] args) {
		String str = SocketInterface("192.168.3.215",4568,"CMD:0;",5000);
		Scanner userInput = new Scanner(System.in);
		if(str != null){
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(str);}
		}else{
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println("Timeout");			
		}
		
		userInput.hasNext();
		
	    str = SocketInterface("192.168.3.215",4568,"CMD:1;ID:C569647F;SOLARIUMID:1",5000);
		if(str != null){
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(str);}
		}else{
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println("Timeout");	}		
		}

		userInput.hasNext();
		
	    str = SocketInterface("192.168.3.215",4568,"CMD:2;ID:C569647F;SOLARIUMID:1;TIME:300;CREDIT:200",5000);
		if(str != null){
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(str);}
		}else{
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println("Timeout");	}		
		}
		
		userInput.hasNext();

	}*/

}

